<?php
namespace App\Listener\Order;

use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Event\Annotation\Listener;

/**
 * @Listener 
 */
class RefundListener implements ListenerInterface
{
    public function listen(): array
    {
        return [
            \App\Event\Order\StatusNoEvent::class,
        ];
    }
    
    // 退款
    public function process($event)
    {
        $content = '关闭【' . $event->order->product_name . '】订单';
        
        // 退积分
        $event->user->addMoney('money_make', $event->order->money_make, $content);
        
        // 判断是否支付过
        if($event->order->statusPay())
        {
            // 退到余额
            $event->user->addMoney('money', $event->order->payMoney(), $content);
        }
    }
}